package org.ivwsqii.proxy.jdkDynamicProxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
/**
 * jdk动态代理
 * 	 实现InvocationHandler接口
 * @author wyl
 *	2019年3月25日
 */
public class DynamicProxyFactory implements InvocationHandler {

	private Object target;

	public DynamicProxyFactory(Object obj) {
		this.target = obj;
	}

	public Object getProxyInstance() {
		return Proxy.newProxyInstance(target.getClass().getClassLoader(),
				target.getClass().getInterfaces(), this);
	}

	@Override
	public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
		System.out.println("看车");
		Object invoke = method.invoke(target, args);
		System.out.println("出钱");
		return invoke;
	}

}
